#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int N = 1e5 + 10;
bool vis[N];
vector<int>e[N];
int n, m;
void dfs(int u)
{
	cout << u << " ";
	vis[u] = 1;
	for (auto v : e[u]) {
		if (!vis[v]) {
			dfs(v);
		}
	}
}
void bfs(int u)
{
	queue<int>q;
	q.push(u);
	vis[u] = 1;
	while (q.size()) {
		int t = q.front();
		q.pop();
		cout << t << " ";
		for (auto v : e[t]) {
			if (!vis[v]) {
				vis[v] = 1;
				q.push(v);
			}
		}
	}
}
int main()
{
	cin >> n >> m;
	while (m--) {
		int u, v;
		scanf_s("%d%d", &u, &v);
		e[u].push_back(v);
	}
	for (int i = 1; i <= n; i++) {
		sort(e[i].begin(), e[i].end());
	}
	dfs(1);
	cout << endl;
	memset(vis, 0, sizeof(vis));
	bfs(1);
	
	return 0;
}